//
//  AppDelegate.m
//  Korea
//
//  Created by 崔剑 on 15/8/21.
//  Copyright (c) 2015年 KoreaGo. All rights reserved.
//

#import "AppDelegate.h"
// 视图
#import "RecomViewController.h"
#import "FeatureViewController.h"
#import "CollectionViewController.h"
#import "LoginViewController.h"
#import "PersonalViewController.h"
#import "UIColor+RGBColor.h"

// 分享
#import "UMSocial.h"

#import <ShareSDK/ShareSDK.h>
#import "WXApi.h"
#import "WeiboSDK.h"
#import <QZoneConnection/QZoneConnection.h>
#import <RennSDK/RennSDK.h>
#import <TencentWeiboConnection/TencentWeiboConnection.h>
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    [self creatView];
    [self shareSDK];
    [UMSocialData setAppKey:@"55f14909e0f55a172a001f7c"];
    
    
    
    
    return YES;
}
- (void)creatView{
    
    self.KoreaTabBarController = [[UITabBarController alloc] init];
    self.window.rootViewController = _KoreaTabBarController;
    // 精选
    RecomViewController *recommendVC = [[RecomViewController alloc] init];
    UINavigationController *recommendNC = [[UINavigationController alloc] initWithRootViewController:recommendVC];
    recommendVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"首页" image:[[UIImage imageNamed:@"home@2x.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"home2@2x.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    // 专辑
    FeatureViewController *featureVC = [[FeatureViewController alloc] init];
    UINavigationController *featureNC = [[UINavigationController alloc] initWithRootViewController:featureVC];
    featureVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"专辑" image:[[UIImage imageNamed:@"special@2x.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"special2@2x.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    // 收藏
    CollectionViewController *collectionVC = [[CollectionViewController alloc] init];
    UINavigationController *collectionNC = [[UINavigationController alloc] initWithRootViewController:collectionVC];
    collectionVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"收藏" image:[[UIImage imageNamed:@"collection@2x.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"collection2@2x.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    // 个人中心
    PersonalViewController *personalVC = [[PersonalViewController alloc] init];
    UINavigationController *personalNC = [[UINavigationController alloc] initWithRootViewController:personalVC];
    personalVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我的" image:[[UIImage imageNamed:@"personal@2x.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"personal2@2x.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    
    
    _KoreaTabBarController.viewControllers = @[recommendNC, featureNC, collectionNC, personalNC];
    
    // 改变TabBar字体颜色
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor grayColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
    UIColor *titleHighlightedColor = [UIColor colorWithRGB:0xfe868f alpha:1];
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:titleHighlightedColor, NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
    
    // 设置TabBar为不透明
    _KoreaTabBarController.tabBar.translucent = NO;
    
    
    //选择白色
    UIColor * color = [UIColor whiteColor];
    
    //设置颜色
    NSDictionary * dict = [NSDictionary dictionaryWithObject:color forKey:NSForegroundColorAttributeName];
    
    //设置导航栏title颜色
    recommendNC.navigationBar.titleTextAttributes = dict;
    featureNC.navigationBar.titleTextAttributes = dict;
    collectionNC.navigationBar.titleTextAttributes = dict;
    personalNC.navigationBar.titleTextAttributes = dict;
    
    // 设置导航栏背景颜色
    recommendNC.navigationBar.barTintColor = [UIColor colorWithRGB:0xfe868f alpha:1];
    featureNC.navigationBar.barTintColor = [UIColor colorWithRGB:0xfe868f alpha:1];
    collectionNC.navigationBar.barTintColor = [UIColor colorWithRGB:0xfe868f alpha:1];
    personalNC.navigationBar.barTintColor = [UIColor colorWithRGB:0xfe868f alpha:1];
    
}
// 分享初始化
- (void)shareSDK{
    [ShareSDK registerApp:@"9f02356a02ce"];
    // 新浪微博
    [ShareSDK connectSinaWeiboWithAppKey:@"568898243"
                               appSecret:@"38a4f8204cc784f81f9f0daaf31e02e3"
                            redirectUri:@"http://www.sharesdk.cn"];
    // 腾讯微博
    [ShareSDK connectTencentWeiboWithAppKey:@"801307650"
                                  appSecret:@"ae36f4ee3946e1cbb98d6965b0b2ff5c"
                                redirectUri:@"http://www.sharesdk.cn"];
    // 人人网
    [ShareSDK connectRenRenWithAppId:@"226427"
                              appKey:@"fc5b8aed373c4c27a05b712acba0f8c3"
                           appSecret:@"f29df781abdd4f49beca5a2194676ca4"
                   renrenClientClass:[RennClient class]];
    // 微信
    [ShareSDK connectWeChatWithAppId:@"wx4868b35061f87885"
                           appSecret:@"64020361b8ec4c99936c0e3999a9f249"
                           wechatCls:[WXApi class]];
    
    // 微信好友
    [ShareSDK connectWeChatSessionWithAppId:@""
                                  appSecret:@""
                                  wechatCls:[WXApi class]];
    // 微信朋友圈
    [ShareSDK connectWeChatTimelineWithAppId:@""
                                   appSecret:@""
                                   wechatCls:[WXApi class]];
    
    
}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    // Saves changes in the application's managed object context before the application terminates.
}


@end
